package com.deliveryservicesystem.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 * File Name: Delivery.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.model.newpackage
 * Author: Lance
 * Date: Jun 24, 2012
 * Editor:
 */
@Entity
@Table(name = "DELIVERY")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Delivery.findAll", query = "SELECT d FROM Delivery d"),
    @NamedQuery(name = "Delivery.findByDeliveryNo", query = "SELECT d FROM Delivery d WHERE d.deliveryNo = :deliveryNo"),
    @NamedQuery(name = "Delivery.findByDeliveryDate", query = "SELECT d FROM Delivery d WHERE d.deliveryDate = :deliveryDate"),
    @NamedQuery(name = "Delivery.findByIsDelivered", query = "SELECT d FROM Delivery d WHERE d.isDelivered = :isDelivered")
})
public class Delivery implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "SEQ_DELIVERY_NO", sequenceName = "SEQ_DELIVERY_NO")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_DELIVERY_NO")
    @Basic(optional = false)
    @Column(name = "DELIVERY_NO")
    private Integer deliveryNo;
    @Column(name = "DELIVERY_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date deliveryDate;
    @Column(name = "IS_DELIVERED")
    private Character isDelivered;
    @OneToMany(mappedBy = "deliveryNo")
    private List<Route> routeList;
    @OneToMany(mappedBy = "deliveryNo")
    private List<Subscription> subscriptionList;
    @JoinColumn(name = "DRIVER_NO", referencedColumnName = "DRIVER_NO")
    @ManyToOne
    private Driver driverNo;

    public Delivery()
    {
    }

    public Delivery(Integer deliveryNo)
    {
        this.deliveryNo = deliveryNo;
    }

    public Integer getDeliveryNo()
    {
        return deliveryNo;
    }

    public void setDeliveryNo(Integer deliveryNo)
    {
        this.deliveryNo = deliveryNo;
    }

    public Date getDeliveryDate()
    {
        return deliveryDate;
    }

    public void setDeliveryDate(Date deliveryDate)
    {
        this.deliveryDate = deliveryDate;
    }

    public Character getIsDelivered()
    {
        return isDelivered;
    }

    public void setIsDelivered(Character isDelivered)
    {
        this.isDelivered = isDelivered;
    }

    @XmlTransient
    public List<Route> getRouteList()
    {
        return routeList;
    }

    public void setRouteList(List<Route> routeList)
    {
        this.routeList = routeList;
    }

    @XmlTransient
    public List<Subscription> getSubscriptionList()
    {
        return subscriptionList;
    }

    public void setSubscriptionList(List<Subscription> subscriptionList)
    {
        this.subscriptionList = subscriptionList;
    }

    public Driver getDriverNo()
    {
        return driverNo;
    }

    public void setDriverNo(Driver driverNo)
    {
        this.driverNo = driverNo;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (deliveryNo != null ? deliveryNo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Delivery))
        {
            return false;
        }
        Delivery other = (Delivery) object;
        if ((this.deliveryNo == null && other.deliveryNo != null) || (this.deliveryNo != null && !this.deliveryNo.equals(other.deliveryNo)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "Delivery Number: " + deliveryNo
                + "\nDelivery Date: " + deliveryDate
                + "\nIs Delivered: " + isDelivered
                + "\nDriver Number " + driverNo.getDriverNo();
    }
}
